package org.dfg.corejava.designPattern.thread.lock;

import java.nio.ByteBuffer;
import java.util.concurrent.locks.ReentrantLock;

public class LockTestReader extends Thread {
	private ByteBuffer bb;
	private ReentrantLock lock;

	public LockTestReader(ByteBuffer bb, ReentrantLock lock) {
		this.bb = bb;
		this.lock = lock;
	}

	@Override
	public void run() {// 模拟读，尝试获取锁
		try {
			lock.lockInterruptibly();//如果线程未中断，尝试获取锁
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		try {
			System.out.println("read end");
		} finally {
			lock.unlock();
		}
	}

}
